<?php
/**
 * @package YARBB
 * @copyright Авторские права (C) 2009 www.yar-it.com. Все права защищены.
 * @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
 * YARBB! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
 * Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл copyright.php.
 */
// no direct access
defined( '_VALID_MOS' ) or die();

// последняя регистрация
$sql = 'SELECT id, username FROM #__users ORDER BY registerDate DESC LIMIT 1';
$_l_u = $database->setQuery($sql)->loadAssocList();
$stats['last_user'] = $_l_u[0];
unset($_l_u);

// число тем и сообщений
$sql = 'SELECT SUM(num_topics) AS num_topics, SUM(num_posts) AS num_posts FROM #__forum_forums';
$_t_t_t = $database->setQuery($sql)->loadAssocList();
$stats['total_topics'] = $_t_t_t[0]['num_topics'];
$stats['total_posts'] = $_t_t_t[0]['num_posts'];
unset($_t_t_t);


// список пользователй в сети >
if ($yarbb_config['o_users_online'] == 1) {
	$num_guests = 0;
	$users = array();
	$now = time();
	$timelimit = $now - $yarbb_config['o_timeout_visit'];
	$sql = 'SELECT userid, username, guest FROM #__session WHERE time >= '. $timelimit. ' ORDER BY gid';
	$online_users = $database->setQuery($sql)->loadObjectList();
	foreach($online_users as $online_user) {
		if ( $online_user->guest == 0) {
			$users[] = '<a href="'.sefRelToAbs('index.php?option=com_users&task=profile&amp;user='.$online_user->userid.':'.$online_users->username).'">'.yarbb_htmlspecialchars($online_user->username).'</a>';
		} else {
			++$num_guests;
		}
	}
	$num_users = count($users);
	$stats['on_line'] = '';

	$stats['on_line'] .= ''. _Y_YARONLINE.': <strong>'.$num_users.'</strong>'."\n\t\t\t\t".''._Y_YARGUESTONLINE.': <strong>'.$num_guests.'</strong>'."\n\t\t\t".''."\n";
	if ($num_users > 0) {
		$stats['on_line'] .= '<div id="onlinelist" class= "clearb"><strong>'._Y_YARUSERONLINE.':&nbsp;</strong>'."\t\t\t\t".implode(', ', $users).''."\n\t\t\t".'</div>'."\n";
	} else {
		$stats['on_line'] .= '<div class="clearer"></div>'."\n";
	}
} else {
	$stats['on_line'] .= '<div class="clearer"></div>'."\n";
}
// список пользователй в сети <


// If no footer style has been specified, we use the default (only copyright/debug info)
$footer_style = isset($footer_style) ? $footer_style : NULL;

// главная страница и страница поиска
$stats['main_page'] ='';
if ($footer_style == 'index' || $footer_style == 'search') {
	if (!$yarbb_user['is_guest']) {
		$stats['main_page'] .= "\n\t\t\t".'<div id="searchlinks" >'."\n\t\t\t\t".'<strong>'._Y_YARNAVIGAT.'</strong>'."\n\t\t\t\t".'<a href="'.sefRelToAbs(YARBB_URL.'&amp;task=search&amp;action=show_24h').'">'._Y_YARLATEST_POST.'</a>'."\n";
		$stats['main_page'] .= "\t\t\t\t".'<a href="'.sefRelToAbs(YARBB_URL.'&amp;task=search&amp;action=show_unanswered').'">'._Y_YARLATEST_POSTNOR.'</a>'."\n";
		if ($yarbb_config['o_subscriptions'] == '1') {
			$stats['main_page'] .= "\t\t\t\t".'<a href="'.sefRelToAbs(YARBB_URL.'&amp;task=search&amp;action=show_subscriptions').'">'._Y_YARMYSUBSCR.'</a>'."\n";
			$stats['main_page'] .= "\t\t\t\t".'<a href="'.sefRelToAbs(YARBB_URL.'&amp;task=search&amp;action=show_user&amp;user_id='.$yarbb_user['id']).'">'._Y_YARMYPOSTS.'</a>'."\n\t\t\t".'</div>'."\n";
		}
	} else {
		if ($yarbb_user['g_search'] == '1') {
			$stats['main_page'] .= "\n\t\t\t".'<div id="searchlinks">'."\n\t\t\t\t".'<strong>'._Y_YARNAVIGAT.'</strong>'."\n\t\t\t\t".'<a href="'.sefRelToAbs(YARBB_URL.'&amp;task=search&amp;action=show_24h').'">'._Y_YARLATEST_POST.'</a>'."\n\t\t\t".'</div>'."\n";
		}
	}
} else if ($footer_style == 'viewforum' || $footer_style == 'viewtopic') {
	$stats['main_page'] .= "\n\t\t\t".'<div class="conl">'."\n";
	if ($footer_style == 'viewforum' && $is_admmod)
		$stats['main_page'] .= "\t\t\t".'<p id="modcontrols"><a href="'.sefRelToAbs(YARBB_URL.'&amp;task=moderate&amp;fid='.$forum_id.'&amp;p='.$p).'">'._Y_YARMODERS.'</a></p>'."\n";

	else if ($footer_style == 'viewtopic' && $is_admmod) {

		$stats['main_page'] .= "\t\t\t".'<div id="modcontrols"><strong>'._Y_YARMODERS.'</strong>: <a href="'.sefRelToAbs(YARBB_URL.'&amp;task=moderate&amp;fid='.$forum_id.'&amp;tid='.$id.'&amp;p='.$p).'">'._Y_YAR_DELNESK.'</a>'."\n";
		$stats['main_page'] .= "\t\t\t".'<a href="'.sefRelToAbs(YARBB_URL.'&amp;task=moderate&amp;fid='.$forum_id.'&amp;move_topics='.$id).'">'._Y_YAR_MOVE.'</a>'."\n";
		if ($cur_topic['closed'] == '1')
			$stats['main_page'] .= "\t\t\t".'<a href="'.sefRelToAbs(YARBB_URL.'&amp;task=moderate&amp;fid='.$forum_id.'&amp;open='.$id).'">'._Y_YAROPENTOP.'</a>'."\n";
		else
			$stats['main_page'] .= "\t\t\t".'<a href="'.sefRelToAbs(YARBB_URL.'&amp;task=moderate&amp;fid='.$forum_id.'&amp;close='.$id).'">'._Y_YARCLOSETOP.'</a>'."\n";
		if ($cur_topic['sticky'] == '1')
			$stats['main_page'] .= "\t\t\t".'<a href="'.sefRelToAbs(YARBB_URL.'&amp;task=moderate&amp;fid='.$forum_id.'&amp;unstick='.$id).'">'._Y_YARSTYKITOP2.'</a></div>'."\n";
		else
			$stats['main_page'] .= "\t\t\t".'<a href="'.sefRelToAbs(YARBB_URL.'&amp;task=moderate&amp;fid='.$forum_id.'&amp;stick='.$id).'">'._Y_YARSTYKITOP.'</a></div>'."\n";
	}
	$stats['main_page'] .= "\t\t\t".'</div>'."\n";
}

// самые активные посетители >
$stats['super_users'] = '';
if ($yarbb_config['o_top_ten'] == 1) {
	$popLimit = $yarbb_config['o_top_post_count'];
	$sql = 'SELECT u.id, u.username FROM #__forum_users as fu
	INNER JOIN #__users AS u ON u.id=fu.id
	WHERE u.id<>1 ORDER BY fu.num_posts DESC, u.username DESC LIMIT '.$popLimit;
	$active_users = $database->setQuery($sql)->loadObjectList();
	foreach ($active_users as $active_user) {
		$stats['super_users'] .= '<a href='.'"'.sefRelToAbs('index.php?option=com_users&task=profile&amp;user='.$active_user->id).'">'.$active_user->username.'</a> ';
	}
	unset($active_users,$active_user);
}
// самые активные посетители <

// счетчик постов >
$sql = "SELECT COUNT(*) FROM #__forum_posts WHERE posted > ".(time()-7*24*3600);
$posts_week = $database->setQuery($sql)->loadResult();

$sql = "SELECT COUNT(*) FROM #__forum_posts WHERE posted > ".(time()-24*3600);
$posts_day = $database->setQuery($sql)->loadResult();
$posts_h = $posts_day/24;

$stats['posts_stats'] = '';
if ($posts_h < 1) {
	if ($posts_day<1) {
		if ($posts_week>1) {
			$stats['posts_stats'] .= _Y_YARWEEK.': <strong>'.$posts_week;
		}
	} else {
		$stats['posts_stats'] .= _Y_YARDAY.': <strong>'.$posts_day;
	}
} else {
	$stats['posts_stats'] .= _Y_YARDAYHOUR.': <strong>'.number_format($posts_h,1);
}
// счетчик постов <

// подключаем низ форума
//ob_start();
//$tpl_footer = include(JPATH_BASE.'/components/com_forum/theme/'.$yarbb_config['o_default_style'].'/footer.tpl');
//$tpl_footer = trim(ob_get_contents());
//ob_end_clean();

//$tpl_main = str_replace('<yarbb_footer>', $tpl_footer, $tpl_main);


// всё, выводим финальную часть
//echo $tpl_main;
